home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVIPS_55 / dvips / src / c / fontdef < prev    next >
Text File  |  1994-05-06  |  5KB  |  194 lines

  1. /*
  2.  *  Stores the data from a font definition into the global data structures.
  3.  *  A routine skipnop is also included to handle nops and font definitions
  4.  *  between pages.
  5.  */
  6. #include "dvips.h" /* The copyright notice in that file is included too! */
  7. /*
  8.  *   These are the external routines we call.
  9.  */
  10. extern shalfword dvibyte() ;
  11. extern halfword twobytes() ;
  12. extern integer threebytes(), signedquad() ;
  13. extern void skipover(), error() ;
  14. /*
  15.  *   The external variables we use:
  16.  */
  17. extern char *nextstring, *maxstring ;
  18. extern integer mag ;
  19. extern fontdesctype *baseFonts[] ;
  20. #ifdef DEBUG
  21. extern integer debug_flag;
  22. #endif  /* DEBUG */
  23. extern int actualdpi ;
  24. extern real alpha ;
  25. extern fontmaptype *ffont ;
  26. extern fontdesctype *fonthead ;
  27. extern halfword dpicheck() ;
  28. extern integer fsizetol ;
  29. /*
  30.  * newfontdesc creates a new font descriptor with the given parameters and
  31.  * returns a pointer to the new object.
  32. */
  33. fontdesctype*
  34. newfontdesc(cksum, scsize, dssize, name, area)
  35. integer cksum, scsize, dssize ;
  36. char *name, *area ;
  37. {
  38.    register fontdesctype *fp ;
  39.  
  40.    fp = (fontdesctype *)mymalloc((integer)sizeof(fontdesctype)) ;
  41.    fp->psname = 0 ;
  42.    fp->loaded = 0 ;
  43.    fp->checksum = cksum ;
  44.    fp->scaledsize = scsize ;
  45.    fp->designsize = dssize ;
  46.    fp->thinspace = scsize / 6 ;
  47.    fp->scalename = NULL ;
  48.    fp->psflag = 0 ;
  49.    fp->name = name;
  50. #ifdef VMCMS   /* IBM: VM/CMS */
  51.    {
  52.      int i ;
  53.      for ( i=0 ; fp->name[i] ; i++ )
  54.        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
  55.    }
  56. #else
  57. #ifdef MVSXA   /* IBM: MVS/XA */
  58.    {
  59.      int i ;
  60.      for ( i=0 ; fp->name[i] ; i++ )
  61.        fp->name[i] = ascii2ebcdic[ fp->name[i] ] ;
  62.    }
  63. #endif   /* IBM: MVS/XA */
  64. #endif   /* IBM: VM/CMS */
  65.    fp->area = area;
  66.    fp->resfont = NULL ;
  67.    fp->localfonts = NULL ;
  68.    fp->dpi = dpicheck((halfword)((float)mag*(float)fp->scaledsize*DPI/
  69.          ((float)fp->designsize*1000.0)+0.5)) ;
  70.    fp->loadeddpi = fp->dpi ;
  71. #ifdef DEBUG
  72.    if (dd(D_FONTS))
  73.       (void)fprintf(stderr,"Defining font (%s) %s at %.1fpt\n",
  74.          area, name, (real)scsize/(alpha*0x100000)) ;
  75. #endif /* DEBUG */
  76.    return fp ;
  77. }
  78. /*
  79.  * Try to find a font with a given name and approximate scaled size, returning
  80.  * NULL if unsuccessful.  If scname and the font's scalename are both
  81.  * non-NULL they must match exactly.  If both are NULL, scsize and the
  82.  * font's scaledsize come from the dvi file and should match exactly.
  83.  * Otherwise there can be some slop due to the inaccuracies of sizes
  84.  * read from an included psfile.
  85.  */
  86. fontdesctype *
  87. matchfont(name, area, scsize, scname)
  88. char *area, *name, *scname ;
  89. integer scsize ;
  90. {
  91.    register fontdesctype *fp;
  92.    register integer smin, smax;
  93.  
  94.    smin = scsize - fsizetol ;
  95.    smax = scsize + fsizetol ;
  96.    for (fp=fonthead; fp; fp=fp->next)
  97.       if (smin < fp->scaledsize && fp->scaledsize < smax &&
  98.             strcmp(name,fp->name)==0 && strcmp(area,fp->area)==0)
  99.          if (scname == NULL) {
  100.             if (fp->scalename!=NULL || scsize==fp->scaledsize)
  101.                break ;
  102.          } else {
  103.             if (fp->scalename==NULL || strcmp(scname,fp->scalename)==0)
  104.                break ;
  105.          }
  106. #ifdef DEBUG
  107.    if (dd(D_FONTS) && fp)
  108.       (void)fprintf(stderr,"(Already known.)\n") ;
  109. #endif /* DEBUG */
  110.    return fp;
  111. }
  112. /*
  113.  *   fontdef takes a font definition in the dvi file and loads the data
  114.  *   into its data structures.
  115.  */
  116. void
  117. fontdef(siz)
  118. int siz ;
  119. {
  120.    register integer i, j, fn ;
  121.    register fontdesctype *fp ;
  122.    register fontmaptype *cfnt ;
  123.    char *name, *area ;
  124.    integer cksum, scsize, dssize ;
  125.    extern void skipover() ;
  126.  
  127.    fn = dvibyte() ;
  128.    while (siz-- > 1)
  129.       fn = (fn << 8) + dvibyte() ;
  130.    for (cfnt=ffont; cfnt; cfnt = cfnt->next)
  131.       if (cfnt->fontnum == fn) goto alreadydefined ;
  132.    cfnt = (fontmaptype *)mymalloc((integer)sizeof(fontmaptype)) ;
  133.    cfnt->next = ffont ;
  134.    ffont = cfnt ;
  135.    cfnt->fontnum = fn ;
  136.    cksum = signedquad() ;
  137.    scsize = signedquad() ;
  138.    dssize = signedquad() ;
  139.    i = dvibyte() ; j = dvibyte() ;
  140.    if (nextstring + i + j > maxstring)
  141.       error("! out of string space") ;
  142.    area = nextstring ;
  143.    for (; i>0; i--)
  144.       *nextstring++ = dvibyte() ;
  145.    *nextstring++ = 0 ;
  146.    name = nextstring ;
  147.    for (; j>0; j--)
  148.       *nextstring++ = dvibyte() ;
  149.    *nextstring++ = 0 ;
  150.    fp = matchfont(name, area, scsize, (integer)0) ;
  151.    if (fp) {
  152.       nextstring = name ;
  153.       fp->checksum = cksum ;
  154.    } else {
  155.       fp = newfontdesc(cksum, scsize, dssize, name, area) ;
  156.       fp->next = fonthead ;
  157.       fonthead = fp ;
  158.    }
  159.    cfnt->desc = fp ;
  160.    if (fn < 256)
  161.       baseFonts[fn] = fp ;
  162.    return ;
  163. alreadydefined:
  164. /* A DVI file will not define a font twice; but we may be scanning
  165.  * a font definition twice because a new section has started,
  166.  * or because of collated copies. */
  167.       skipover(12) ;
  168.       skipover(dvibyte()+dvibyte()) ;
  169. }
  170.  
  171. /*
  172.  *   The next routine handles nops or font definitions between pages in a
  173.  *   dvi file.  Returns the first command that is not a nop or font definition.
  174.  *
  175.  *   Now handles specials (but ignores them)
  176.  */
  177. int
  178. skipnop()
  179. {
  180.   register int cmd ;
  181.  
  182.    while (1) {
  183.       switch(cmd=dvibyte()) {
  184. case 138: break ;
  185. case 239: skipover((int)dvibyte()) ; break ; /* xxx1 */
  186. case 240: skipover((int)twobytes()) ; break ; /* xxx2 */
  187. case 241: skipover((int)threebytes()) ; break ; /* xxx3 */
  188. case 242: skipover((int)signedquad()) ; break ; /* xxx4 */
  189. case 243: case 244: case 245: case 246: fontdef(cmd-242) ; break ;
  190. default: return cmd ;
  191.       }
  192.    }
  193. }
  194.